<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- 讲师介绍 开始 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">讲师介绍</span>
        </h2>
      </header>
      <div class="t-infor-wrap">
        <!-- 讲师基本信息 开始 -->
        <section class="fl t-infor-box c-desc-content">
          <div class="mt20 ml20">
            <section class="t-infor-pic">
              <img v-if="teacher.avatar" :src="teacher.avatar" :alt="teacher.name">
              <img v-else :alt="teacher.name" src="~/assets/photo/teacher/222.jpg">
            </section>
            <h3 class="hLh30">
              <span class="fsize24 c-333">{{ teacher.name }}
                &nbsp;{{ teacher.level===1?'高级讲师':'首席讲师' }}
              </span>
            </h3>
            <section class="mt10">
              <span class="t-tag-bg">{{ teacher.career }}</span>
            </section>
            <section class="t-infor-txt">
              <p class="mt20">{{ teacher.intro }}</p>
            </section>
            <div class="clear"/>
          </div>
        </section>
        <!-- /讲师基本信息 结束 -->
        <div class="clear"/>
      </div>
      <section class="mt30">
        <div>
          <header class="comm-title all-teacher-title c-course-content">
            <h2 class="fl tac">
              <span class="c-333">主讲课程</span>
            </h2>
            <section class="c-tab-title">
              <a href="javascript: void(0)">&nbsp;</a>
            </section>
          </header>
          <!-- 无数据提示 开始-->
          <section v-if="!courses||courses.length===0" class="no-data-wrap" >
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam">没有相关数据，小编正在努力整理中...</span>
          </section>
          <!-- /无数据提示 结束-->

          <!-- 课程列表 开始-->
          <article class="comm-course-list">
            <ul class="of">
              <li v-for="course in courses" :key="course.id" >
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img :alt="course.title" :src="course.cover" class="img-responsive">
                    <div class="cc-mask">
                      <a href="/course/1" title="开始学习" class="comm-btn c-btn-1">开始学习</a>
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a :title="course.title" href="/course/1" class="course-title fsize18 c-333">{{ course.title }}</a>
                  </h3>
                </div>
              </li>
            </ul>
            <div class="clear"/>
          </article>
          <!-- /课程列表 结束-->
        </div>
      </section>
    </section>
    <!-- /讲师介绍 结束 -->
  </div>
</template>
<script>
/*
    vue对象属于js代码，代码都在浏览器中执行，所以vue对象的初始化是在浏览器中初始化的
    asyncData()在nuxt服务器中执行，执行时vue对象还未初始化
  */
import teacherApi from '~/api/teacher'
export default {
  async asyncData(ctx) { // ctx代表nuxt调用该方法时传入的上下文对象，封装了访问当前页面的所有数据+路由信息
    // console.log(ctx)
    const response = await teacherApi.getById(ctx.params.id)
    const asd = await teacherApi.getCourseByTeacherId(ctx.params.id)
    // console.log(response.data)
    return {
      teacher: response.data.item,
      courses: asd.data.items
    }
  }
  // data() {
  //   return {
  //     teacher: {
  //     }
  //   }
  // }
  // created() {
  //   teacherApi.getById(this.$route.params.id).then(r => {
  //     this.teacher = r.data.item
  //   })
  // }
}
</script>
